﻿

using Grishko.DataTier;
using OutdoorLib.Context;
using OutdoorLib.BaseEntity.Face;
namespace OutdoorLib.BaseEntity.WS
{
public class wsFace :EntitySingle 
{

    public wsFace()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    
    public FaceEntity GetFace(string FaceID)
    {
        if (!CacheTools.IsCacheObject(FaceID))
        {
            FaceEntity p = new FaceEntity();
            p.ID = FaceID;
            p.Load();
            CacheTools.SetCacheObject(FaceID, p);
            return p;
        }

        return (FaceEntity)CacheTools.GetCacheObect(FaceID);

    }


    
    public ContactFace  GetContactFace(string FaceID)
    {
        if (!CacheTools.IsCacheObject(FaceID))
        {
            ContactFace p = new ContactFace();
            p.ID = FaceID;
            if (!AgencyLib_GlobalConstants.IsNewRecord(FaceID)) p.Load();
            CacheTools.SetCacheObject(FaceID, p);
            return p;
        }

        return (ContactFace)CacheTools.GetCacheObect(FaceID);

    }

    
    public ContactFaceList GetContactFaceList(ContactFaceList.sqlLoadStatment WhereStatment)
    {
        ContactFaceList list = new ContactFaceList();
        list.SqlStatment = WhereStatment;
        list.Load();
        return list;
    }

        
    public Employeer GetNewEmpl(string ID)
    {
        if (!CacheTools.IsCacheObject(ID))
        {
            Employeer p = new Employeer();
            p.ID = ID ;
            CacheTools.SetCacheObject(ID, p);
            return p;
        }

        return (Employeer)CacheTools.GetCacheObect(ID);

    }


    
    public Employeer  GetEmpl(string ID)
    {
        if (!CacheTools.IsCacheObject(ID))
        {
            Employeer p = new Employeer();
            p.ID = ID;
            p.Load();
            CacheTools.SetCacheObject(ID, p);
            return p;
        }

        return (Employeer)CacheTools.GetCacheObect(ID);

    }

    
    public Client  GetClient(string ID)
    {
        if (!CacheTools.IsCacheObject(ID))
        {
            Client  p = new Client();
            p.ID = ID;
            p.Load();
            CacheTools.SetCacheObject(ID, p);
            return p;
        }

        return (Client)CacheTools.GetCacheObect(ID);

    }


    
    //public EmployeeList GetEmplList(EmployeeList.MyListWhere  Where)
    //{
    //    EmployeeList  list = new EmployeeList ();
        
    //    list.ListWhere = Where;        
    //    list.Load();
    //    return list;
    //}

   
    public ClientList GetClientList(ClientList .sqlLoadStatment  Where)
    {
        ClientList  list = new ClientList ();
        list.SqlStatment = Where;
        list.Load();
        return list;

    }


   

   
    public FaceEntity  SaveFace(FaceEntity _Face)
    {
        if ( AgencyLib_GlobalConstants.IsNewRecord(_Face.ID))//режим вставки?
        {
            string s = _Face.ID;
            _Face.ID = _Face.ID.Replace(AgencyLib_GlobalConstants.qPrefNEW_RECORD, string .Empty );
            _Face.Save();
            CacheTools.ResetCache(s);
            return _Face;
        }
        // асинхонно сохраняемся
        //_Face.Save();
        _Face.Save(AppContext.GetSC ().ConnectionString);
        _Face.SetHash();
        return _Face;
        
    }

   

}
}
